'''
7
8 6 5 7 10 8 11
'''

from dataclasses import dataclass
from typing import Optional


@dataclass
class Node:
    val: int
    left: Optional['Node'] = None
    right: Optional['Node'] = None


def buildTree(order: list):
    if len(order) == 0:
        return None

    root = Node(order[0])

    if len(order) == 1:
        return root
    loc = 0
    for index, i in enumerate(order[1:]):
        if order[0] <= i:
            loc = index + 1
            break
    root.left = buildTree(order[1:loc])
    root.right = buildTree(order[loc:])
    return root


def buildTree_2(order: list):
    if len(order) == 0:
        return None

    root = Node(order[0])

    if len(order) == 1:
        return root
    loc = 0
    for index, i in enumerate(order[1:]):
        if order[0] > i:
            loc = index + 1
            break
    root.left = buildTree_2(order[1:loc])
    root.right = buildTree_2(order[loc:])
    return root


list1 = []


def back_order(root: Node):
    list1.append(root.val)
    if root.right:
        back_order(root.right)
    if root.left:
        back_order(root.left)


n = int(input())
nums = list(map(int, input().split()))
not_reverse = (nums[0] < nums[1])
if not_reverse:
    t = buildTree(nums)
else:
    t = buildTree_2(nums)

back_order(t)
if len(list1) != n:
    print('NO')
else:
    print('YES')
    if not not_reverse:
        list1.reverse()
    print(*list1)
